package com.lizemin.custom.classloader.encrypt.impl;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import com.lizemin.custom.classloader.encrypt.Encryptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;

import java.nio.charset.StandardCharsets;

/**
 * @author lzm
 * @date 2025/6/2 14:24
 * @description  AES算法实现
 */
public class AesEncryptor implements Encryptor {

    private static final Logger log = LoggerFactory.getLogger(AesEncryptor.class);

    @Override
    public String encrypt(String plaintext) {
        log.info("开始使用AES算法加密明文{}", plaintext);
        AES aes = SecureUtil.aes();
        byte[] encrypt = aes.encrypt(plaintext.getBytes(StandardCharsets.UTF_8));
        return Base64Utils.encodeToString(encrypt);
    }

}
